/* 
$(function(){

	$("map  area").each(function(i){
		alert(i);   
		$(this).mouseover(function(e){

			$m_name = $(this).attr("name");				
			alert($m_name);

			$($m_name)
			.css({
				"display:block;"
				"top": (e.pageY+20) + "px",
				"left": (e.pageX+10)  + "px"
			}).show("fast");			

				
		}).mouseout function(){
				
			$($m_name)
			.css({
				"display:none;"
			
			})
			});
	   });
})
*/	

$(function(){
    var m_x = 5;  
	var m_y = 5;
	var m_name;
	
	
	$("map  area").mouseover(function(e){		
		
		m_name = $(this).attr("name");
		//alert(m_name);

		$(".map img").attr("src",public+"images/theme/market/"+m_name+".gif");
		//alert("../images/theme/market/"+m_name+".gif");
		$("#"+m_name).show();

		t_coord = getCoords(e,m_name);
		//alert(t_coord[1]);
		$("#"+m_name).css({
				"opacity": 0.9,
				"top": t_coord[1] + "px",
				"left": t_coord[0]  + "px"
			});
		
		
		
    }).mousemove(function(e){
		
		t_coord = getCoords(e,m_name);

		$("#"+m_name)
			.css({
				"top": t_coord[1] + "px",
				"left": t_coord[0]  + "px"
			});
		
	}).mouseout(function(){			
		
		$(".map img").attr("src",public+"images/theme/market/china_bak.gif");
		$("#"+m_name).hide();
		
    });
});


function getCoords(e,t_name){
	
	var max_width = $(window).width();	
	var max_height = $(window).height();
	
	var scroll_h = $(document).scrollTop();
	var scroll_w = $(document).scrollLeft();	
	//alert(scroll_h);
	var tips_width = $("#"+t_name).width();
	var tips_height = $("#"+t_name).height();
	
	//alert("max_height = " + max_height + "\n tips_height = " + tips_height + "\n e.pageY = " + e.pageY);
	//alert((e.pageY + tips_height) - max_height);
	
	var tips_Coords = new Array();
	
	
	if(e.pageX + tips_width <= max_width){
		tips_Coords[0] = e.pageX + 5;
	}
	else{
		tips_Coords[0] = max_width - tips_width;
		
	}

	
	
	if(e.pageY + tips_height <= max_height + scroll_h){
		tips_Coords[1] = e.pageY+5;
	}
	else{
		over_h = (e.pageY + tips_height) - (max_height + scroll_h);	
		
		tips_Coords[1] = e.pageY - over_h;
		
	}

	

	return tips_Coords;

}
